<template>
  <div class="container">
    <div class="title" style=" text-align: left;">新建资讯新闻</div>
    <div class="wrap">
      <el-row>
        <el-col :lg="16" :md="20" :sm="24" :xs="24">
          <el-form :model="form" status-icon ref="form" label-width="100px" @submit.native.prevent>
            <el-form-item label="资讯标题" prop="title">
              <el-input size="medium" v-model="form.title" placeholder="请填资讯标题,保存后不允许在修改标题"></el-input>
            </el-form-item>
            <el-form-item label="资讯内容" prop="content">
<!--              <el-input size="medium" type="textarea" :autosize="{ minRows: 4, maxRows: 8 }" placeholder="请输入资讯内容"
                        v-model="form.content">
              </el-input>-->
              <tinymce upload_url="http://dev.lin.colorful3.com/recruit/file/" />
            </el-form-item>
            <el-form-item class="submit">
              <el-button type="primary" @click="submitForm('form')" :loading="loading">保 存</el-button>
              <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { Info } from '@/model/info'
import Tinymce from '@/component/base/tinymce'

export default {
  data() {
    return {
      form: {
      },
      loading: false,
    }
  },
  components: {
    Tinymce,
  },
  methods: {
    async submitForm(formName) {
      try {
        this.loading = true
        const res = await Info.create(this.form)
        this.loading = false
        if (res.code < window.MAX_SUCCESS_CODE) {
          this.$message.success(`${res.message}`)
          // 清空输入框，方便继续添加
          this.resetForm(formName)
        }
      } catch (error) {
        this.loading = false
        console.log(error)
      }
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
  },
}
</script>

<style lang="scss" scoped>
.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;
    border-bottom: 1px solid #dae1ec;
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
</style>
